package com.share.rules.api.factory;

import com.share.common.core.domain.R;
import com.share.rules.api.RemoteFeeRuleService;
import com.share.rules.api.domain.FeeRule;
import com.share.rules.api.domain.FeeRuleRequestForm;
import com.share.rules.api.domain.FeeRuleResponseVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Slf4j
public class RemoteFeeRuleFallbackFactory implements FallbackFactory<RemoteFeeRuleService> {
    @Override
    public RemoteFeeRuleService create(Throwable throwable) {
        return new RemoteFeeRuleService() {
            @Override
            public R<List<FeeRule>> getFeeRuleList(List<Long> feeRuleIdList) {
                log.error("获取费用规则列表失败，参数: {}, 异常: {}", feeRuleIdList, throwable.getMessage(), throwable);
                return R.fail("获取费用规则列表失败:" + throwable.getMessage());
            }

            @Override
            public R<FeeRule> getFeeRule(Long id) {
                log.error("获取费用规则信息失败，参数: {}, 异常: {}", id, throwable.getMessage(), throwable);
                return R.fail("获取费用规则信息失败:" + throwable.getMessage());
            }

            @Override
            public R<FeeRuleResponseVo> calculateOrderFee(FeeRuleRequestForm feeRuleRequestForm) {
                return R.fail("费用计算失败:" + throwable.getMessage());
            }
        };
    }
}
